package cn.lcc.basic.controller;

import cn.lcc.basic.exception.BusinessException;
import cn.lcc.basic.service.IVerifyCodeService;
import cn.lcc.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 验证码接口类
 */
@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 接口：图形验证码
     * @param key
     * @return
     */
    @GetMapping("/image/{key}")
    public String getImageCode(@PathVariable("key") String key){

        return verifyCodeService.getImageCode(key);
    }
    @PostMapping("/smsCode")
    public AjaxResult getSmsCode(@RequestBody Map<String ,String> map){
        try {
            verifyCodeService.getSmsCode(map);
            return new AjaxResult();
        } catch (BusinessException e) {
            return new AjaxResult(false,e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"系统繁忙,请稍后重试!!!");
        }
    }
    @PostMapping("/binderSmsCode")
    public AjaxResult getBinderSmsCode(@RequestBody Map<String ,String> map){
        try {
            verifyCodeService.getBinderSmsCode(map);
            return new AjaxResult();
        } catch (BusinessException e) {
            return new AjaxResult(false,e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"系统繁忙,请稍后重试!!!");
        }
    }
}